package t327.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import t327.pojo.Fee;
import t327.pojo.QuotationList;
import t327.pojo.StyleNumber;
import t327.pojo.VerifyPrice;
import t327.pojo.font.LuiTableEntity;
import t327.service.iter.IQuotationService;

import java.util.List;

@RestController
@RequestMapping("quotationManager")
public class QuotationController {
        @Autowired
        IQuotationService quotationService;

        @RequestMapping("verifyPriceAdd")  //核价单提交
        @ResponseBody
    public String quotationAdd(@RequestBody VerifyPrice verifyPrice){
//        List<Long> listId=verifyPrice.getListId();
//        HashMap<Object,Object>map=quotationService.getFeeStyleNumber(verifyPrice.getStyleNumberId(),li);

        int i = quotationService.quotationAdd(verifyPrice);
        if (i > 0){
            return "success";
        }
        return "false";
    }

    @RequestMapping("feeAdd") //费用提交
    @ResponseBody
    public String feeAdd(@RequestBody Fee fee , Long styleNumberId){
        int i = quotationService.feeAdd(fee);
        if (i > 0){
            long feeId = fee.getFeeId();
            int j = quotationService.getFeeStyleNumber(styleNumberId, feeId);
            if (j>0){
                int updateAddStatusInStyleNumber = quotationService.updateAddStatusInStyleNumber(styleNumberId);
                if (updateAddStatusInStyleNumber>0){
                    return "success";
                }
            }
        }
        return "false";
    }

    @RequestMapping("getAllStyleNumber") //获取款号
    @ResponseBody
    public List<StyleNumber> getAllStyleNumber(){
        List<StyleNumber> allStyleNumber = quotationService.getAllStyleNumber();
        return allStyleNumber;
    }

    @RequestMapping("getBrandByStyleNumber")
    @ResponseBody
    public List<StyleNumber> getBrandByStyleNumber (Long styleNumberId){
        return quotationService.getBrandByStyleNumber(styleNumberId);
    }

    @RequestMapping("getAllQuotation") //查询全部
    public LuiTableEntity getOrderColorSizeClient(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
/*
*     "code": res.status, //解析接口状态
      "msg": res.message, //解析提示文本
      "count": res.total, //解析数据长度
      "data": res.data.item //解析数据列表
* */
        PageHelper.startPage(pageNum,pageSize);
        LuiTableEntity luiTableEntity = new LuiTableEntity<QuotationList>();
        PageInfo<QuotationList> orderColorSizeClientview = new PageInfo<>(quotationService.getAllQuotationList());
        List<QuotationList> products = orderColorSizeClientview.getList();
        long total = orderColorSizeClientview.getTotal();
        if(products!=null&&products.size()>0){
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(products);
        }else{
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");

        }
        System.out.println("1");
        System.out.println(products);
        return   luiTableEntity;

    }

    @RequestMapping("getQuotationListByCond") //条件查询全部
    @ResponseBody
    public List<QuotationList> getQuotationListByCond(@RequestParam("styleNumber")String styleNumber){
        List<QuotationList> quotationListByCond = quotationService.getQuotationListByCond(styleNumber);
        return quotationListByCond;
    }

    @RequestMapping("changeAuditStatus")
    @ResponseBody
    public int changeAuditStatus(Long styleNumberId){return quotationService.changeAuditStatus(styleNumberId);}
}
